<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Acl
 *
 * @author neozilon
 */
class Nosql_Controller_Plugin_AclModule extends Zend_Controller_Plugin_Abstract {

    private $_acl;


    public function  __construct() {
        $this->_acl = Nosql_Acl_ModuleAcl::getInstance();
    }

    public function  preDispatch(Zend_Controller_Request_Abstract $request){
        $module = $request->getModuleName();
        $controller = $request->getControllerName();
        $action = $request->getActionName();

        $role = Nosql_Acl_ModuleAcl::ROLE_GUEST;

        //check for user session
        if ( Zend_Auth::getInstance()->hasIdentity() ){
            $user = Zend_Auth::getInstance()->getIdentity();
            $role = $user->role;
        }

        if (! $this->_acl->isAllowed($role, $module . $controller, $action)){
            if ($module == 'admin'){
                $this->_response->setRedirect('/admin/login/index/err/1');
            }else{
                $this->_response->setRedirect('/');
            }
        }
        
    }
}